import re
import uuid

from mongoengine import QuerySet, Q

def select_meeting(queryset, id=None, meeting=None, info=None):
    if not (id or meeting or info):
        return None
    result = queryset
    if id is not None:
        result = result.filter(id=id)
    if meeting is not None:
        result = result.filter(meeting__icontains=meeting)
    if info is not None:
        result = result(Q(introduction__icontains=info) | Q(themes__report__icontains=info) | Q(themes__keywords__icontains=info))
    return result

def select_subject(queryset, id=None, meeting=None, report=None, keywords=None, org=None, speaker=None):
    if not (id or meeting or report or keywords or org or speaker):
        return None
    result = queryset
    if id is not None:
        result = result.filter(id=id)
    if meeting is not None:
        result = result.filter(meeting__icontains=meeting)
    if speaker is not None:
        result = result.filter(speaker=speaker)
    if report is not None:
        result = result.filter(report__icontains=report)
    if org is not None:
        result = result.filter(org__icontains=org)
    if keywords is not None:
        result = result.filter(keywords__icontains=keywords)
    return result
